package com.yonyou.pmclouds.auditlog.rmiimpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.yonyou.pmclouds.ApplicationConsts;
import com.yonyou.pmclouds.auditlog.entity.AuditLogVO;
import com.yonyou.pmclouds.auditlog.mapper.AuditLogMapper;
import com.yonyou.pmclouds.auditlog.service.IAuditLogMaintain;
import com.yonyou.pmclouds.basecom.bp.processor.AuditInfoInsertProcessor;
import com.yonyou.pmclouds.basecom.bp.template.SingleInsertBpTemplate;
import com.yonyou.pmclouds.basecom.consts.BillTypeConst;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.picture.entity.PictureParamVO;
import com.yonyou.pmclouds.picture.rmiitf.PictureRemoteService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author th
 * @date 2019/10/25 12:43
 */
@Service(interfaceClass = IAuditLogMaintain.class, version = ApplicationConsts.APPLICATION_VERSION)
public class AuditLogMaintainImpl implements IAuditLogMaintain {

    @Autowired
    private AuditLogMapper mapper;
    @Autowired
    private PictureRemoteService picService;

    @Override
    public AuditLogVO add(AuditLogVO vo) throws BusinessException {
        if (vo == null)
            return null;

        // 保存验收记录
        SingleInsertBpTemplate<AuditLogVO> bpTemplate = new SingleInsertBpTemplate<>(mapper);
        bpTemplate.addBeforeProcessor(new AuditInfoInsertProcessor<AuditLogVO>());
        bpTemplate.insert(vo);

        // 保存验收图片
        PictureParamVO paramVO = new PictureParamVO(vo.getPkBill(), vo.getPkProject(),
                BillTypeConst.PROBLEMLOG_BILLTYPE);
        picService.insertPictureForPub(vo, paramVO);

        return vo;
    }

}
